package moniCA;
use strict;
use Log::Log4perl qw(:easy);
use Params::Validate qw(:all);
use vars qw( $VERSION );
$VERSION = '2.11';

sub new {
	my $this  = shift;
	my $class = ref($this) || $this;
	my $self  = {};
	bless $self, $class;
	return $self;
}

sub SetUp {
	my $self     = shift;
	my $LogLevel = $self->LogLevel();
	my $Logger   = Log::Log4perl::get_logger( ref $self );
	Log::Log4perl::MDC->put( 'Plug', $self->Plug() );
	my %LogLevel = (
		DEBUG => sub { $Logger->level($Log::Log4perl::DEBUG) },
		INFO  => sub { $Logger->level($Log::Log4perl::INFO) },
		WARN  => sub { $Logger->level($Log::Log4perl::WARN) },
		ERROR => sub { $Logger->level($Log::Log4perl::ERROR) },
		FATAL => sub { $Logger->level($Log::Log4perl::FATAL) }
	);
	$LogLevel{$LogLevel}->() if exists $LogLevel{$LogLevel};
	$self->{Logger} = $Logger;
	return $self;
}

#############  Sub Setter/Getter methods  #############
sub GetLogger {
	my $self = shift;
	return $self->{Logger};
}

sub GetCNF {
	my $self = shift;
	return $self->{CNF};
}

sub SetCNF {
	my $self = shift;
	Params::Validate::validation_options( allow_extra => 1 );
	$self->{CNF} = validate(
		@_,
		{
			Modul  => { type => SCALAR },
			Logger => { type => SCALAR, default => "moniCA" },
			LogLevel => {
				type    => SCALAR,
				default => "INFO",
				regex   => qr/^(FATAL||ERROR||WARN||INFO||DEBUG||TRACE)$/
			},
			Subject  => { type => SCALAR, optional => 1 },
			Description => { type => SCALAR, optional => 1 },

		}
	);
	return $self;
}

sub Plug {
	my $self = shift;
	if (@_) { $self->{Plug} = shift }
	return $self->{Plug};
}

sub PackageFile {
	my $self = shift;
	if (@_) { $self->{PackageFile} = shift }
	return $self->{PackageFile};
}

sub Desc {
	my $self = shift;
	if (@_) { $self->{Desc} = shift }
	return $self->{Desc};
}

sub LogLevel {
	my $self = shift;
	if (@_) { $self->{Logger} = shift }
	return $self->{Logger};
}

sub ProductDir {
	my $self = shift;
	if (@_) { $self->{ProductDir} = shift }
	return $self->{ProductDir};
}

sub EtcDir {
	my $self = shift;
	if (@_) { $self->{EtcDir} = shift }
	return $self->{EtcDir};
}

sub TmpDir {
	my $self = shift;
	if (@_) { $self->{EtcDir} = shift }
	return $self->{EtcDir};
}

sub VarDir {
	my $self = shift;
	if (@_) { $self->{VarDir} = shift }
	return $self->{VarDir};
}

sub LogDir {
	my $self = shift;
	if (@_) { $self->{LogDir} = shift }
	return $self->{LogDir};
}

1;
